package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/22 16:01
 **/
public class Day20_1_Num1640_CanFormArray {
    class Solution {
        public boolean canFormArray(int[] arr, int[][] pieces) {
            for(int i = 0; i < arr.length; ++i){
                int start = findInd(arr[i], pieces);
                if(start == -1) return false;
                for(int j = 0; j < pieces[start].length; ++j){
                    if(arr[i + j] != pieces[start][j]){
                        return false;
                    }
                }
                // i循环还要++，所以先-1
                i += pieces[start].length-1;
            }
            return true;
        }
        // 找到 arr 中元素在 pieces 的位置
        private int findInd(int target, int[][] pieces){
            for(int i = 0; i < pieces.length; ++i){
                if(pieces[i][0] == target) return i;
            }
            return -1;
        }
    }
}